package avicit.bdp.dgs.metadata.compare.pojo;

import avicit.bdp.common.service.dto.BdpTableDTO;
import org.apache.commons.lang3.StringUtils;

/**
 * 数据表变更明细
 *
 * @author mayi
 */
public class MetadataTableDiffItem extends DiffItem<BdpTableDTO> {

  public static final String NO = "NO";
  public static final String CREATE = "CREATE";
  public static final String ALTER = "ALTER";
  public static final String DROP = "DROP";

  public MetadataTableDiffItem(BdpTableDTO ot, BdpTableDTO nt) {
    super(ot, nt);
    if (nt != null) {
      setKey(nt.getDataSourceId() + "." + nt.getName());
    } else {
      setKey(ot.getDataSourceId() + "." + ot.getName());
    }
    if (ot == null && nt != null) {
      setType(CREATE);
    } else if (ot != null && nt != null) {
      setType(ALTER);
      if (StringUtils.equals(ot.getRemark(), nt.getRemark())) {
        setType(NO);
      }
    } else if (ot != null && nt == null) {
      setType(DROP);
    }
  }
}
